package com.feng.common.controller;

import com.alibaba.fastjson.JSON;
import com.feng.common.util.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* @Description: CommonController 公共的控制类，这里面写的是所有控制类都需要使用的方法
* @Author: xing
* @Date: 2023/2/6 15:17
*/
public class CommonController {


    /*
    * @Description: commonException
    * 统一的Controller层的异常处理
    * @Param: [runtimeException]
    * @return: java.lang.String
    * @Author: xing
    * @Date: 2023/2/6 15:31
    */
    @ExceptionHandler
    @ResponseBody
    public String commonException(RuntimeException runtimeException){
        Result result = new Result();
        result.setCode("-1");
        result.setMsg(runtimeException.toString());
        return JSON.toJSONString(result);
    }


    /**
     * 返回登录
     * @param s
     * @param success
     * @param o
     * @return
     */
    protected String return_success(String s, String success, Object o) {
        Result result=new Result();
        result.setCode("1");
        result.setMsg("登录成功");
        return JSON.toJSONString(result);
    }

    protected String return_error() {
        Result result=new Result();
        result.setCode("0");
        result.setMsg("登录失败");
        return JSON.toJSONString(result);
    }
}
